{include file="header.htm" /}
<body class="bodystyle">
<div id="append_parent"></div>
<div id="ajaxwaitid"></div>
<div class="page min-hg-c-50">
    <div class="flexigrid">
        <div class="header-bar flexigrid-xin">
            <div class="more">
                <div class="search">
                    <div class="content">
                        <form id="searchForm" action="{:weapp_url('Seckill/Seckill/ajax_archives_list')}" method="get" onsubmit="layer_loading('正在处理');" style="display: unset;">
                            {$searchform.hidden|default=''}

                            <div class="ey-form-item"><label class="users-form-item-label">关键词：</label>
                                <div class="users-form-item-content">
                                    <div class="users-select">
                                        <div tabindex="0" class="users-select-selection">
                                            <div class="sDiv2">
                                                <input type="text" size="50" name="keywords" value="{$Request.param.keywords}" class="qsbox" style="width: 170px;" placeholder="用户名">
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <div class="ey-form-item " style="position: relative !important;">
                                <label class="users-form-item-label">商品分类：</label>
                                <div class="users-form-item-content" id="goodsStypeid">
                                    <div class="users-select">
                                        <div class="users-select-selection">
                                            <div class="sDiv2 ">
                                                <input type="text" class="qsbox fenlei" placeholder="{$stypeidCount|default='全部'}" lay-key="1" style="width: 210px;" id="stypeidCount">
                                                <i class=" layui-icon-down layui-icon" style="position: absolute;top: 9px;right: 10px;color: #444343; font-size: 10px;font-weight: bold;"></i>
                                            </div>
                                        </div>
                                        <div id="ey_fenleitanchuang" style="display: none;" onselectstart="return false;">
                                            <table class="flex-table autoht" cellpadding="0" cellspacing="0" border="0" id="arctype_table" style="width: 100%">
                                                <tbody id="treet1">
                                                {foreach name="arctype_list" item="vo" key="k" }
                                                <tr nctype="0" {if condition="!in_array($vo.parent_id,$tree.cookied_treeclicked) && 0 < $vo.parent_id "} style="display:none;"{/if} class="parent_id_{$vo['parent_id']}" data-level="{$vo['level']}" data-id="{$vo['id']}">
                                                <td class="typename" style="width: 100%">
                                                    <div style="margin: 10px 0;">
                                                        {eq name='vo.level' value='1'}<span class="" style="margin-left: 20px;"></span>{/eq}
                                                        {egt name='vo.level' value='2'}<span class="" style="margin-left: 40px;"></span>{/egt}
                                                        {gt name="vo.has_children" value="0"}
                                                        <img src="{in name='$vo.id' value='$tree.cookied_treeclicked'}__SKIN__/images/tv-collapsable-last.gif{else /}__SKIN__/images/tv-expandable.gif{/in}" style="float: none;" fieldid="2" status="open" nc_type="flex" onclick="treeClicked(this, {$vo['id']}, 0);" class="has_children childrenImg" data-level="{$vo['level']}" data-id="{$vo['id']}">
                                                        {else /}
                                                        <img src="__SKIN__/images/tv-collapsable-last.gif" style="float: none;" fieldid="2" status="open" nc_type="flex" class="childrenImg">
                                                        {/gt}
                                                        <label><input type="checkbox" name="stypeid[]" value="{$vo.id}" id="{$vo.id}" data-level="{$vo.level}" data-topid="{$vo.topid}" data-parent_id="{$vo.parent_id}" data-typename="{$vo.typename}" data-has_children="{$vo.has_children}" onclick="selectStypeid(this);" class="stypeid {eq name='$vo.level' value='1'} topid_{$vo.topid} {/eq}">&nbsp;{$vo.typename}</label>
                                                    </div>
                                                </td>
                                                </tr>
                                                {/foreach}
                                                </tbody>
                                            </table>
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <div class="ey-form-item" style="margin-left: 20px;">
                                <div class="users-form-item-content">
                                    <span class="bt-xin" onclick="OrderQuery();">查询</span>
                                    <span class="bt-xin-no" onclick="OrderQuery('reset');">重置</span>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
            
        </div>
        <div class="hDiv mt10">
            <div class="hDivBox">
                <table cellspacing="0" cellpadding="0" style="width: 100%">
                    <thead>
                    <tr>
                        <th abbr="article_title" axis="col3">
                            <div class="text-l10">商品名称</div>
                        </th>
                        <th abbr="" axis="col4" class="w200">
                            <div class="tc">价格</div>
                        </th>
                        <th abbr="" axis="col6" class="w120">
                            <div class="tc">库存</div>
                        </th>
                        <th abbr="" axis="col6" class="w200">
                            <div class="tc">营销活动</div>
                        </th>
                        <th abbr="" axis="col5" class="w80">
                            <div class="tc">操作</div>
                        </th>
                    </tr>
                    </thead>
                </table>
            </div>
        </div>
        <div class="bDiv" style="height: auto;">
            <div id="flexigrid" cellpadding="0" cellspacing="0" border="0">
                <table style="width: 100%">
                    <tbody>
                    {volist name="list" id="vo"}
                        <tr>
                            <td style="width: 100%;" class="">
                                <div class="flex-row">
                                    <img width="60" height="60" src="{$vo.litpic}">
                                    <div class="ml5">
                                        {$vo.title}
                                    </div>
                                </div>
                            </td>
                            <td>
                                <div class="w200 tc" style="">
                                    <strong>￥{$vo.min_price}{gt name="$vo.max_price" value="0"}~￥{$vo.max_price}{/gt}</strong>
                                </div>
                            </td>
                            <td class="">
                                <div class="w120 tc">
                                    {$vo.stock_count}
                                </div>
                            </td>
                            <td class="">
                                <div class="w200 tc">
                                    <!-- 需做判断 -->
                                    <a class="btn" href="javascript:void(0);"  onclick="openFullframe(this, '查看参与的活动', '1050px', '650px');" data-href="{:weapp_url('Seckill/Seckill/get_join_activity',['aid'=>$vo.aid])}">查看参与的活动</a>
                                    <!-- <span class="curpoin">未参与活动</span> -->
                                </div>
                            </td>
                            <td class="operation">
                                <div class="w80 tc">
                                    {eq name="$vo.temporary_add" value="1"}
                                    <a href="JavaScript:void(0);" class="btn grey">选择</a>
                                    {else/}
                                    <a href="JavaScript:void(0);" data-aid="{$vo.aid}" onclick="selectGoods(this);" class="btn blue" id="aid_{$vo.aid}">选择</a>
                                    {/eq}
                                </div>
                            </td>
                        </tr>
                    {/volist}

                    </tbody>
                </table>
            </div>
            <div class="iDiv" style="display: none;"></div>
        </div>

        {include file="page.htm" /}

        <div class="bot3">
            <div class="item-selected">已选择<span id="selectLength" style="color: red;">0</span>条</div>
            <a href="javascript:void(0);" onclick="parent.submitSelectGoods();" class="ncap-btn-big ncap-btn-green"><span>确认</span></a>
            <a class="ncap-btn-big ncap-btn-no" href="javascript:void(0);" onclick="parent.closeSelectGoods(true);" title="关闭">关闭</a>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function() {
        // 加载已选商品数
        $('#selectLength').text(parent.aidArr.length);
        // 显示已选商品标记
        if (parent.aidArr.length > 0) {
            $.each(parent.aidArr, function(index, value) {
                if ($('#aid_' + value)) $('#aid_' + value).removeClass('blue').addClass('red').html('已选');
            });
        }
    });

    // 点击选中商品
    function selectGoods(obj) {
        // 执行父级页面选中操作
        parent.selectGoods(obj);
        // 加载已选商品数
        $('#selectLength').text(parent.aidArr.length);
    }

    // 订单查询
    function OrderQuery(isReset) {
        if (isReset && 'reset' == isReset) {
            window.location.href = "{:weapp_url('Seckill/Seckill/ajax_archives_list')}";
        } else {
            $('#searchForm').submit();
        }
    }

    $(document).ready(function(){
        // 表格行点击选中切换
        $('#flexigrid > table>tbody >tr').click(function(){
            $(this).toggleClass('trSelected');
        });

        // 点击刷新数据
        $('.fa-refresh').click(function(){
            location.href = location.href;
        });

        $('#searchForm select[name=typeid]').change(function(){
            $('#searchForm').submit();
        });
    });
</script>

<input type="hidden" id="post_stypeid" value="{$stypeidStr}">
<script type="text/javascript">
    $(function() {
        var stypeidStr = $('#post_stypeid').val();
        var stypeidArr = stypeidStr.split(',');
        $('.stypeid').each(function() {
            var _this = $(this);
            var index = $.inArray(String(_this.val()), stypeidArr);
            if (parseInt(index) > -1) {
                _this.attr('checked', true);
                $('#' + _this.data('topid')).attr('checked', true);
                $('#' + _this.data('parent_id')).attr('checked', true);
            }
        });

        $('#goodsStypeid').mouseover(function() {
            $('#ey_fenleitanchuang').show();
        });
        $('#goodsStypeid').mouseout(function() {
            $('#ey_fenleitanchuang').hide();
        });
    });

    function selectStypeid(obj) {
        var isSelect = $(obj).prop('checked');
        var selectID = parseInt($(obj).val());
        var selectLevel = parseInt($(obj).data('level'));
        var selectTopID = parseInt($(obj).data('topid'));
        var selectParentID = parseInt($(obj).data('parent_id'));
        var selectValue1 = selectValue2 = selectValue3 = 0;
        var postStypeidArr = [];
        $('.stypeid').each(function() {
            var _this = $(this);
            if (0 === selectLevel) {
                if (selectID === parseInt(_this.data('topid'))) _this.attr('checked', isSelect);
            } else if (1 === selectLevel) {
                if (selectID === parseInt(_this.data('parent_id'))) _this.attr('checked', isSelect);
            }
            if (1 === selectLevel && 1 === parseInt(_this.data('level')) && selectTopID === parseInt(_this.data('topid'))) {
                if (true === _this.prop('checked')) selectValue1++;
                if (0 === parseInt(selectValue1)) {
                    $('#' + selectTopID).attr('checked', false);
                } else {
                    $('#' + selectTopID).attr('checked', true);
                }
            }
            if (2 === selectLevel && 2 === parseInt(_this.data('level')) && selectParentID === parseInt(_this.data('parent_id'))) {
                if (true === _this.prop('checked')) selectValue2++;
                if (0 === parseInt(selectValue2)) {
                    $('#' + selectParentID).attr('checked', false);
                } else {
                    $('#' + selectTopID).attr('checked', true);
                    $('#' + selectParentID).attr('checked', true);
                }
            }

            // 选中的分类ID加入数组
            if (0 === _this.data('has_children') && true === _this.prop('checked')) postStypeidArr.push(_this.val());
        });

        // 处理二级分类是否选中
        $('.topid_' + selectTopID).each(function() {
            if (true === $(this).prop('checked')) selectValue3++;
        });
        if (0 === parseInt(selectValue3)) $('#' + selectTopID).attr('checked', false);

        // 所有选中的分类数量
        var selectStypeidLength = $('#arctype_table input[name="stypeid[]"]:checked').length;
        if (parseInt(selectStypeidLength) > 0) {
            $('#stypeidCount').attr('placeholder', '已选中 ' + selectStypeidLength + ' 个分类');
        } else {
            $('#stypeidCount').attr('placeholder', '全部');
        }

        // 选中的分类ID数组转字符串
        var postStypeidStr = postStypeidArr.join(',');
        $('#post_stypeid').val(postStypeidStr);
    }
</script>
<script type="text/javascript">
    $(function() {
        setCookies('stypeid-treeClicked-Arr', JSON.stringify({$tree.cookied_treeclicked_arr}) );
    });

    // 点击展开 收缩节点
    function treeClicked(obj, id, reload) {
        if (id == 'all') {
            if (1 == reload) {
                var status = getCookie('stypeid-treeClicked');
                if (!status) status = $(obj).attr('data-status');
            } else {
                var status = $(obj).attr('data-status');
            }
            if (status == 'close') {
                setCookies('stypeid-treeClicked-Arr', JSON.stringify({$tree.parent_ids}));
                setCookies('stypeid-treeClicked_All', 1);//1为全部展开,0-为非全部展开
                $('tr[class^=parent_id_]').show();
                $('.childrenImg').attr('src', '__SKIN__/images/tv-collapsable-last.gif');
                $(obj).attr('data-status', 'open').attr('title','关闭所有子分类').attr('src','__SKIN__/images/tv-collapsable-last.gif');
            } else {
                setCookies('stypeid-treeClicked-Arr', '');
                setCookies('stypeid-treeClicked_All', 0);
                $('tr[data-level=0]').find('img.has_children').attr('src', '__SKIN__/images/tv-collapsable-last.gif').trigger('click');
                $('tr[class^=parent_id_]').removeClass('trSelected');
                $(obj).attr('data-status', 'close').attr('title','展开所有子分类').attr('src','__SKIN__/images/tv-expandable.gif');
            }
            setCookies('stypeid-treeClicked', status);
            return false;
        }

        var src = $(obj).attr('src');
        if (src == '__SKIN__/images/tv-expandable.gif') {
            var arr = [];
            var str = getCookie('stypeid-treeClicked-Arr');
            if ('' == str || null == str || 'null' == str) {
                arr.push(id);
            } else {
                arr = JSON.parse(str);
                if (!arr.includes(id))arr.push(id);
            }
            arr = JSON.stringify(arr);
            setCookies('stypeid-treeClicked-Arr', arr);
            $(".parent_id_"+id).show();
            $(obj).attr('src','__SKIN__/images/tv-collapsable-last.gif');
            var status = 'close';
        } else {
            var key = -1;
            var arr = [];
            var level = '';
            var str = getCookie('stypeid-treeClicked-Arr');
            if ('' != str) {
                arr = JSON.parse(str);
                key = $.inArray(id,arr);
                if (-1 < key) arr.splice(key,1);
                level = $(obj).attr('data-level');
                $(obj).parent().parent().parent().nextAll().each(function() {
                    if ($(this).attr('data-level') > level) {
                        key = $.inArray(parseInt($(this).attr('data-id')), arr);
                        if (-1 < key) arr.splice(key,1);
                    } else {
                        return false;
                    }
                });
                arr = JSON.stringify(arr);
                setCookies('stypeid-treeClicked-Arr', arr);
                setCookies('stypeid-treeClicked_All', 0);
            }

            var status = 'open';
            $(obj).attr('src', '__SKIN__/images/tv-expandable.gif');

            // 如果是点击减号, 遍历循环他下面的所有都关闭
            var fnd = false;
            var cur_tr = obj.parentNode.parentNode.parentNode;
            var tbl = document.getElementById("arctype_table");
            for (var i = 0; i < tbl.rows.length; i++) {
                var row = tbl.rows[i];
                if (row == cur_tr) {
                    fnd = true;
                } else {
                    if (fnd == true) {
                        var cur_level = $(cur_tr).data('level');
                        var level = parseInt($(row).data('level'));
                        if (level > cur_level) {
                            $(row).hide();
                            $(row).find('img.has_children').attr('src','__SKIN__/images/tv-expandable.gif');
                        } else {
                            fnd = false;
                            break;
                        }
                    }
                }
            }
        }
        setCookies('stypeid-treeClicked', status);
    }

</script>
{include file="footer.htm" /}
